/**
 * 共用数据混入
 */
export default {
	data() {
		return {};
	},
	computed: {},
	methods: {
		msg(...args) {
			let iconMap = ['none', 'success', 'error', 'fail', 'exception', 'loading'];
			let icon = 'none';
			let fun = null;
			let duration = 2000;
			let title = '';
			args.forEach((value, index) => {
				if (index === 0 && typeof value === 'string' && !iconMap.includes(value)) title = value;
				if (iconMap.includes(value)) icon = value;
				if (typeof value === 'function') fun = value;
				if (typeof value === 'number') duration = value;
			})
			uni.showToast({
				icon,
				title,
				duration,
				success: () => {
					if (fun && typeof fun === 'function') {
						setTimeout(() => {
							fun();
						}, duration)
					}
				}
			})
		},
		toBack() {
			uni.navigateBack()
		},
		toNav(route) {
			uni.navigateTo({
				url: `/pages/${route}`,
				fail: () => {
					uni.navigateTo({
						url: `/pagesExtend/${route}`
					})
				}
			})
		},
		toTab(route) {
			uni.switchTab({
				url: `/pages/${route}`,
			})
		},
	}
};